﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RenShiKaoQin.Account
{
    public partial class GLForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (hrdbEntities ent = new hrdbEntities())
                {
                    var result = from kqemp in ent.TKQEmployees where kqemp.FEmployeeID.Equals(Page.User.Identity.Name) select kqemp;
                    if (result.Any())
                    {
                        TKQEmployee kq = result.Single();
                        if (!kq.IsAdmin)
                        {
                            Response.Write("您无权查看此页面");
                            Response.End();
                        }

                    }
                    else
                    {
                        Response.Write("您无权查看此页面");
                        Response.End();
                    }
                }
            }
            tbStart.Attributes["readonly"] = "readonly";
            tbEnd.Attributes["readonly"] = "readonly";
            Page.Form.DefaultButton = btnSearchSec.UniqueID;
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow r in gvSQ.Rows)
            {
                gvSQ.UpdateRow(r.RowIndex, false);
            }
        }

        protected void btnSearchSec_Click(object sender, EventArgs e)
        {
            sqlJC.SelectParameters.Clear();
            if (tbNameSec.Text != "")
            {
                sqlJC.SelectParameters.Add("FName", tbNameSec.Text);
                string tmin = DateTime.Now.AddDays(2).ToString("u");
                string tmax = DateTime.Now.AddDays(1).ToString("u");
                sqlJC.SelectParameters.Add("Start", TypeCode.DateTime, tmin.Substring(0, tmin.Length - 1));
                sqlJC.SelectParameters.Add("End", TypeCode.DateTime, tmax.Substring(0, tmax.Length - 1));
            }
            else
            {
                sqlJC.SelectParameters.Add("FName", string.Empty);
                sqlJC.SelectParameters["FName"].ConvertEmptyStringToNull = false;
                sqlJC.SelectParameters.Add("Start", TypeCode.DateTime, tbStart.Text);
                sqlJC.SelectParameters.Add("End", TypeCode.DateTime, tbEnd.Text);
            }
        }

        protected void sqlJC_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
           
        }
    }
}